/**
 * @file Net.c
 * @author liqiang (liqiang@hacint.com.cn)
 * @brief 
 * @version 1.0.0
 * @date 2023-08-16
 * 
 * 
 */

#include "Net.h"
#include "W5500.h"
#include "socket.h"

 /**本地变量*/
#define LOCAL_PORT 30000				/*本机端口*/
unsigned char PcIp[4]= {192,168,0,100};	/*远程主机IP*/
unsigned short int PcPort=8089;			/*远程主机端口*/

u8 tempRxBuf[2048];	//socket接收数据缓冲区

 void	Net_Process(void){
 
		u32 recCnt=0;

		switch(getSn_SR(0))                      	/*获取socket0的状态*/
		{
			case SOCK_UDP: 
				if((recCnt = getSn_RX_RSR(0))>0)    /*receive_length为已接收数据长度*/
				{
					if(recCnt>0x5c8)	
					{
						recCnt=0x5c8;
					}
					recvfrom(0, tempRxBuf, recCnt, PcIp,&PcPort);	 
				}	
			break;
			case SOCK_CLOSED:                           /*socket关闭*/
				socket(0,Sn_MR_UDP,LOCAL_PORT,0);       /*打开socket0的一个端口*/
			break;
		} 
 }


 void	Plat_Net_Process(void){

		Net_Process(); 
 }